package com.pca.headline.dao.impl;

import com.pca.headline.dao.BaseDao;
import com.pca.headline.dao.NewsUserDao;
import com.pca.headline.pojo.NewsUser;

import java.util.List;

public class NewsUserDaoImpl extends BaseDao implements NewsUserDao {
    @Override
    public NewsUser findByUsername(String username) {
        String sql = "select uid,username,user_pwd userPwd,nick_name nickName from news_user where username = ?";
        List<NewsUser> userList = baseQuery(NewsUser.class, sql, username);

        return userList != null && userList.size() > 0 ? userList.get(0) : null;
    }

    @Override
    public NewsUser findByUid(Integer userId) {
        String sql = "select uid,username,user_pwd userPwd,nick_name nickName from news_user where uid = ?";
        List<NewsUser> userList = baseQuery(NewsUser.class, sql, userId);

        return userList != null && userList.size() > 0 ? userList.get(0) : null;
    }

    @Override
    public Integer insertUser(NewsUser user) {
        String sql = "insert into news_user values(default,?,?,?)";
        return baseUpdate(sql,user.getUsername(), user.getUserPwd(), user.getNickName());
    }
}
